package cn.yunbamboos.rest.service.apidoc.meta;

import cn.yunbamboos.rest.service.apidoc.IMeta;
import com.alibaba.fastjson2.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class Components implements IMeta {

    private final Map<String, Schema> schemas = new HashMap<String, Schema>();

    public void put(String key, Schema schema) {
        this.schemas.put(key, schema);
    }

    @Override
    public JSONObject toJSON() {
        JSONObject json = new JSONObject();
        JSONObject schemas = new JSONObject();
        for (Map.Entry<String, Schema> entry : this.schemas.entrySet()) {
            schemas.put(entry.getKey(), entry.getValue().toJSON());
        }
        json.put("schemas", schemas);
        return json;
    }
}
